package controller;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class Connect {

	public static boolean enter(String name,char[] pass) throws IOException		{
		InetAddress server=InetAddress.getByName("noskamaru.no-ip.org");
		//InetAddress server=InetAddress.getByName("localhost");
		int port=4444;
		int newport=0;
		Socket s=null;
		BufferedReader in=null,stdin=null;
		PrintWriter out=null;
		String pwd=String.valueOf(pass);
		try		{
			s=new Socket(server,port);
			out=new PrintWriter(s.getOutputStream(),true);
			in=new BufferedReader(new InputStreamReader(s.getInputStream()));
			stdin=new BufferedReader(new InputStreamReader(System.in));
			out.println(name);
			out.println(pwd);
			newport=Integer.parseInt(in.readLine());
			if(newport!=0)	{
				Convert.port=newport;
				return true;
			}
			else	{
				return false;
			}
		}
		catch(Exception e)		{
				return false;
		}
		finally		{
				stdin.close();
				in.close();
				out.close();
				s.close();
		}
		
	}
}
